import os
from langgraph.prebuilt import create_react_agent
from langchain.chat_models import init_chat_model
from langchain_core.messages import HumanMessage
from langchain_community.tools.tavily_search import TavilySearchResults

os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()
os.environ["LANGSMITH_API_KEY"] = "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"

os.environ["TAVILY_API_KEY"] = "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"

model = init_chat_model(
    model_provider="openai",
    model="qwen/qwq-32b:free",
    base_url="https://openrouter.ai/api/v1",
    api_key="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",
)

search = TavilySearchResults(max_results=2)
# search_results = search.invoke("成都近的天气")
# print(search_results)

tools = [search]

agent_executor = create_react_agent(model, tools)

response = agent_executor.invoke(
    {"messages": [HumanMessage(content="成都今天的天气怎么样")]}
)
